<?php
/**
 * Action methods used by Web_Controller
 */
class Web_Controller_Actions{
	
	
	/**
	 * Reference to controller object
	 * @var object
	 */
	private $controller = null;


	/**
	 * Constructor.
	 * Sets reference to controller object
	 */
	function __construct($controller){

		$this->controller = $controller;
	}
		

	/**
	 * This is default action (like index action).
	 * This action will be called if no other action is requested.
	 */
	function index($url_args){
		$this->controller->check_login();
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}	
	
	
	/**
	 * Login page
	 */
	function login(){		
		$run_plugins['view']['Main_View']['login'] = array();
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}
	
	
	/**
	 * Logout
	 */
	function logout(){
		// kill session and delete cookie
		$_SESSION = array();
		if (isset($_COOKIE[session_name()])) {
			setcookie(session_name(), '', time()-42000, '/');
			$_COOKIE = array();
		}
		session_destroy();
		$this->index(array());
	}
	
	
	/**
	 * Exception
	 */
	function exception($url_args){
		$this->controller->check_login();
		$run_plugins['view']['Main_View']['uncaught_exception'] = array($url_args[1]);
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}
	
	
	/**
	 * Sum
	 */
	function sum($url_args){
		$this->controller->check_login();
		$run_plugins['view']['Example_View']['sum'] = array();
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}
	
	
	/**
	 * Sum with ajax
	 */
	function sumajax($url_args){
		$this->controller->check_login();
		$run_plugins['view']['Example_View']['sum_ajax'] = array();
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}
	
	
	/**
	 * Calculates sum
	 */
	function calculate($url_args){
		$this->controller->check_login();
		$run_plugins['model']['Example']['sum'] = array($_POST['num1'], $_POST['num2']);
		$run_plugins['view']['Example_View']['sum'] = array();
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}
	
	
	/**
	 * Calculates sum with ajax
	 */
	function calculateajax($url_args){
		$this->controller->check_login();
		$run_plugins['model']['Example']['sum'] = array($_POST['num1'], $_POST['num2']);
		$run_plugins['view']['Example_View']['sum_result_ajax'] = array();
		$run_plugins['view']['Main_View']['generate_html'] = array();
		$this->controller->run_plugins($run_plugins);
	}
	
}
